<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" :model="formState" class="form-style-flex" :label-col="{ style: { width: '70px' } }">
        <a-form-item label="" name="zjm" class="w-72">
          <a-input v-model:value="formState.zjm" placeholder="物品编号/物品名称/助记码" />
        </a-form-item>
        <a-form-item label="状态" name="iskcyj" class="w-64">
          <a-select ref="select" v-model:value="formState.iskcyj" placeholder="请选择" allow-clear>
            <a-select-option :value="0">未设置</a-select-option>
            <a-select-option :value="1">已设置</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <!-- <div class="mb-3">
        <a-button @click="onExport">导出</a-button>
      </div> -->
      <BaseTable :loading="loading" :data-source="tableData" bordered :pagination="pagination" fill column-code="000176">
        <template #bodyCell="{ column, record, index }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'mc'">
            <MedicineInfo :value="{ mc: record?.mc, gg: record?.gg, cj: record?.cj }" />
          </template>
          <template v-if="column.dataIndex === 'zjkc'">
            <EditCell>
              <a-input v-model:value="record.zjkc" placeholder="请输入" @blur="onBlurSave(record)" />
            </EditCell>
          </template>
          <template v-if="column.dataIndex === 'aqkc'">
            <EditCell>
              <a-input v-model:value="record.aqkc" placeholder="请输入" @blur="onBlurSave(record)" />
            </EditCell>
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { message } from 'ant-design-vue'
import EditCell from '@/components/EditCell'
import { post } from '@/utils/request'
import SearchContainer from '@/components/SearchContainer'
import BaseTable from '@/components/BaseTable'

const formRef = ref(null)
const formState = ref({
  cxxm: 1
})
const { loading, tableData, getData, pagination } = useTable({
  url: '/oos/psiform/getStorageWarningList',
  immediate: true,
  params: formState.value
})
const onBlurSave = async (record) => {
  const { code, msg } = await post('/oos/psiform/doSaveStorageWarning', record)

  if (code !== 0) return message.error(msg)
  message.success(msg)
  // getData()
}
onMounted(() => {
  //queryList()
})
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
